#ifndef __SARESULT_H__
#define __SARESULT_H__


class SAResult {
public:
	const size_t SABufSize;
	unsigned int numSA;
private:
	uint3* SA;
public:
	SAResult(const size_t i_SABufSize) :
		SABufSize(i_SABufSize) {
		SA = (uint3*)malloc(SABufSize);
		numSA = 0;
	}	
	~SAResult() {
		free(SA);
		numSA = 0;
	}

	inline uint3* getSA() {
		return SA;
	}
	
	void update(uint3* newSA, const unsigned int newNumSA) {
		if(sizeof(uint3)*newNumSA > SABufSize) {
			cout << "!!!ERROR@SAResult::update: sizeof(uint3)*newNumSA > SABufSize";
			exit(-1);
		}

		numSA = newNumSA;
		memcpy(SA, newSA, sizeof(uint3)*numSA);
	}
	
	inline uint3 getSA(const unsigned long i) const {
		return SA[i];
	}

	inline unsigned long getNumAlignment(const unsigned long i) const {
		return SA[i].z - SA[i].y + 1;
	}

	inline uint3* getSAForAppend() {
		return SA + numSA;
	}

	inline void clear() {
		numSA = 0;
	}

	inline unsigned long numAlignment() {
		unsigned long n = 0;
		for(unsigned int i = 0; i < numSA; i++) {
			n += (SA[i].z - SA[i].y + 1);
		}
		return n;
	}

	inline void report() {
		cout << "The number of SA:         " << numSA << endl;
		cout << "The number of alignments: " << numAlignment() << endl;
	}
};

#endif /*__SARESULT_H__*/
